<?php /*a:1:{s:62:"D:\web\www\tp5.1\public/../app/admin\view\auth_rule\index.html";i:1526118281;}*/ ?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>表格</title>
    <link rel="stylesheet" href="/static/frame/layui/css/layui.css">
    <link rel="stylesheet" href="/static/frame/static/css/style.css">
    <link rel="icon" href="/static/frame/static/image/code.png">
</head>
<body class="body">

<div><a class="layui-btn site-demo-active layui-btn-sm" id="addauth" data-href="<?php echo url('admin/AuthRule/add'); ?>"><i class="layui-icon">&#xe608;</i>添加新权限节点</a></div>
<table class="layui-table" lay-filter="parse-table-demo" lay-data="{height:'',url:'<?php echo url('admin/AuthRule/ajaxlist',Request::param()); ?>', page:false, id:'test',limit:'1000'}">
    <thead>
    <tr>
        <th lay-data="{field:'_name', width:250}">节点名称</th>
        <th lay-data="{field:'name', minwidth:300}">节点地址</th>
        <th lay-data="{field:'status', width:80, templet: '#statusTpl', unresize: true}">状态</th>
        <th lay-data="{field:'ismenu', width:100,templet: '#ismenuTpl', unresize: true}">是否菜单</th>
        <th lay-data="{field:'icon', width:120, templet:'#layuiIcon'}">图标</th>
        <th lay-data="{field:'sorts', width:80,edit: 'text', sort: true}">排序</th>
        <th lay-data="{fixed: 'right', width:128, align:'center', toolbar: '#barDemo'}">操作</th>
    </tr>
    </thead>
</table>

<script type="text/html" id="barDemo">
  <a class="layui-btn layui-btn-xs" lay-event="edit"><i class="layui-icon">&#xe642;</i></a>
  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon">&#xe640;</i></a>
</script>

<script type="text/html" id="statusTpl">
  <input type="checkbox" name="status" value="{{d.id}}" lay-skin="switch" lay-text="禁|否" lay-filter="lockstatus" {{ d.status == 0 ? 'checked' : '' }}>
</script>

<script type="text/html" id="ismenuTpl">
  <input type="checkbox" name="ismenu" value="{{d.id}}" lay-skin="switch" lay-text="是|否" lay-filter="lockismenu" {{ d.ismenu == 1 ? 'checked' : '' }}>
</script>

<script type="text/html" id="layuiIcon">
  <i class="layui-icon {{d.icon}}"></i>
</script>

<script type="text/javascript" src="/static/frame/layui/layui.js"></script>
<script src="/static/admin/js/comm.js" charset="utf-8"></script>
<script type="text/javascript">
layui.use(['form','table','admin'], function(){
  var $ = layui.jquery
      ,form = layui.form
      ,table = layui.table;
  

  //监听单元格编辑
  table.on('edit(parse-table-demo)', function(obj){
    //console.log('d','dss')
    var value = obj.value //得到修改后的值
    ,data = obj.data; //得到所在行所有键值

    //layer.msg('[ID: '+ data.id +'] ' + field + ' 字段更改为：'+ value);
    $.post('<?php echo url('admin/AuthRule/quickedit'); ?>',{id:data.id,sorts:value},function(data){
        if(data.code == 1){
          //alert('dd');
            layer.msg(data.msg);
        }
    });

  });

//添加
    $('#addauth').click(function(){
      layer.open({
        title: "权限节点修改",
        type: 2,
        area: ['450px', '500px'],
        fixed: false, //不固定
        maxmin: true,
        content: "<?php echo url('admin/AuthRule/add'); ?>"
      });
    });


  //监听工具条
  table.on('tool(parse-table-demo)', function(obj){
    var data = obj.data;
    if(obj.event === 'del'){
      layer.confirm('真的删除行么', function(index){
        $.get("<?php echo url('admin/AuthRule/delete'); ?>?id=" + data.id,function(data){
        if (data.code == 1) {
          layer.msg(data.msg);
          obj.del();
          layer.close(index);
        }
        });
        // window.location.href='<?php echo url('delete','',false); ?>/id/'+data.id ;
        // obj.del();
        // layer.close(index);
      });
    } else if(obj.event === 'edit'){

      layer.open({
        title: "权限节点修改",
        type: 2,
        area: ['450px', '500px'],
        fixed: false, //不固定
        maxmin: true,
        content: "<?php echo url('admin/AuthRule/edit'); ?>?id=" + data.id
      });

      //window.location.href='<?php echo url('edit','',false); ?>/id/'+data.id ;
      //layer.alert('编辑行：<br>'+ data.id)
    }
  });

  //监听锁定操作
  form.on('switch(lockismenu)', function(obj){
    if(obj.elem.checked === true){
        ismenuval =1;
    }else{
        ismenuval =0;
    }
    $.post('<?php echo url('admin/AuthRule/quickedit'); ?>',{id:this.value,ismenu:ismenuval},function(data){
        if(data.code == 1){
            layer.tips(data.msg, obj.othis);
        }
    });
  });

  //监听锁定操作
  form.on('switch(lockstatus)', function(obj){
    if(obj.elem.checked === true){
        statusval =0;
    }else{
        statusval =1;
    }
    $.post('<?php echo url('admin/AuthRule/quickedit'); ?>',{id:this.value,status:statusval},function(data){
        if(data.code == 1){
            layer.tips(data.msg, obj.othis);
        }
    });



  });
  
  // var $ = layui.$, active = {
  //   getCheckData: function(){ //获取选中数据
  //     var checkStatus = table.checkStatus('idTest')
  //     ,data = checkStatus.data;
  //     layer.alert(JSON.stringify(data));
  //   }
  // };
  
  // $('.demoTable .layui-btn').on('click', function(){
  //   var type = $(this).data('type');
  //   active[type] ? active[type].call(this) : '';
  // });

  
});
</script>
</body>
</html>